package com.itc.system.controller;

import com.itc.common.core.domain.R;
import com.itc.common.core.validate.Add;
import com.itc.common.core.validate.Update;
import com.itc.system.api.domain.SysDept;
import com.itc.system.api.domain.dto.SysDeptCheckDto;
import com.itc.system.domain.dto.SysDeptMenuDto;
import com.itc.system.domain.vo.TreeSelectDept;
import com.itc.system.service.SysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dept")
@Api(tags = "部门管理")
public class SysDeptController {

    @Autowired
    private SysDeptService sysDeptService;

    /**
     * 席位绑定权限菜单
     * @param dto
     * @return
     */
    @ApiOperation(value = "席位绑定权限菜单")
    @PostMapping("/menu/bind")
    public R menuBind(@Validated @RequestBody SysDeptMenuDto dto){
        return sysDeptService.menuBind(dto);
    }

    /**
     * 添加部门
     * @param sysDept
     * @return
     */
    @ApiOperation(value = "添加部门")
    @PostMapping("/add")
    public R addDept(@Validated(Add.class) @RequestBody SysDept sysDept){
        return sysDeptService.addDept(sysDept);
    }

    /**
     * 根据id删除部门
     * @param deptId
     * @return
     */
    @ApiOperation(value = "根据id删除部门")
    @DeleteMapping("/delete/{deptId}")
    public R removeDept(@PathVariable(value = "deptId") Long deptId){
        return sysDeptService.removeDept(deptId);
    }

    /**
     * 获取部门信息详情
     * @param deptId
     * @return
     */
    @ApiOperation(value = "获取部门信息详情")
    @GetMapping("/detail/{deptId}")
    public R<SysDept> getDetail(@PathVariable(value = "deptId") Long deptId){
        return sysDeptService.getDetail(deptId);
    }

    /**
     * 修改部门
     * @param sysDept
     * @return
     */
    @ApiOperation(value = "修改部门")
    @PostMapping("/update")
    public R updateDept(@Validated(Update.class) @RequestBody SysDept sysDept){
        return sysDeptService.updateDept(sysDept);
    }

    /**
     * 查询部门所有树形
     * @param sysDept
     * @return
     */
    @ApiOperation(value = "查询部门所有树形")
    @PostMapping("/tree/all")
    public R<List<SysDept>> listTrees(@RequestBody SysDept sysDept){
        List<SysDept> sysDepts = sysDeptService.selectDeptTreeList(sysDept);
        return R.ok(sysDepts);
    }

    /**
     * 查询部门所有树形，只显示部门名称
     * @param sysDept
     * @return
     */
    @ApiOperation(value = "查询部门所有树形，只显示部门名称")
    @PostMapping("/tree")
    public R<List<TreeSelectDept>> listTree(@RequestBody SysDept sysDept){
        List<TreeSelectDept> sysDepts = sysDeptService.selectDeptTree(sysDept);
        return R.ok(sysDepts);
    }

    /**
     * 根据部门席位信息查询所属席位信息,包括部门
     * @param sysDept
     * @return
     */
    @ApiOperation(value = "根据部门席位信息查询所属席位信息/,包括部门")
    @PostMapping("/seat/list")
    public R<List<SysDept>> getSeatListByDeptId(@RequestBody SysDeptCheckDto sysDept){
        return R.ok(sysDeptService.getSeatListByDeptId(sysDept));
    }


}
